<?php
 /**
 *  +---------------------------------------------------------------------- 
 *  | 文件功能：返回前台消息提示工具集合
 *  +---------------------------------------------------------------------- 
 *  | Copyright (c) 2022~2024 https://www.huihuiv.com All rights reserved.
 *  +---------------------------------------------------------------------- 
 *  | Create At: 2024年02月26日 18:09:06
 *  +---------------------------------------------------------------------- 
 *  | Author: 半壶水 <star@cqshanwen.com>
 *  +---------------------------------------------------------------------- 
 */

namespace App\Librarys;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;

class Message{
    
    /**
     * 返回前台带数据JSON消息
     *
     * @param boolean $success
     * @param string $message
     * @param mixed $data
     * @param integer $status
     * @param array $headers
     * @param integer $options
     * @return JsonResponse
     */
    public static function show(bool $success = false, string $message = '返回无意义空消息', mixed $data = [], int $status = 200, array $headers = [], int $options = 0): JsonResponse
    {
        return response()->json(['success' => $success, 'message' => $message, 'data' => $data], $status, $headers, $options);
    }

    /**
     * 返回TOKEN信息
     *
     * @param boolean $success
     * @param string $message
     * @param string $token
     * @return JsonResponse
     */
    public static function token(bool $success = false, string $message = 'token获取失败', string $token = ''): JsonResponse
    {
        return response()->json(['success' => $success, 'message' => $message, 'token' => [
            'access_token' => $token,
            'token_type' => 'bearer',
            'expires_in' => Auth::guard('api')->factory()->getTTL() * 60
        ]]);
    }

    /**
     * 返回上传文件信息
     *
     * @param integer $status
     * @param string $message
     * @param string $url
     * @return JsonResponse
     */
    public static function upload(int $status = 1, string $message = '文件上传失败', string $url): JsonResponse
    {
        return response()->json([
            'errno' => $status,
            'message' => $message,
            'data' => [
                'url' => $url
            ]
        ]);
    }
}